package com.jixu.numberapp.controller;

import com.jixu.numberapp.entity.Game;
import com.jixu.numberapp.service.NumberService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.Future;

@RestController
@RequestMapping("gameinfo")
@Slf4j
public class GameController {
    @Autowired
    private NumberService service;
    @Autowired
    ThreadPoolTaskExecutor executor;

    @PostMapping("/joinGame")
    public Game joinGame(@RequestBody Game game) {
        Future<?> submit = executor.submit(new Thread(() -> {
            service.beginGame(game, executor);
        }));
        return game;
    }
}

